# !/bin/bash

# 限定为 服务根目录为 www
# 前端项目线上放进 frontweb下再区分环境
# 使用传参数 sit or prod   sh front.sh sit

# # git npm dist
gitPath="/usr/bin/git"
npmPath="/usr/bin/npm /opt/node-v10.16.3-linux-x64/bin/npm"

svn update

npm install

npm run build
# serverRoot="/Users/macbook/Documents/www/"
# projectName="h5-tool-admin"
# projectRoot="${serverRoot}/${env}/${projectName}"
# frontPath="${projectRoot}/front"

# # git npm dist
# gitPath="/usr/bin/git"
# npmPath="/Users/macbook/.nvm/versions/node/v12.12.0/bin/cnpm"
# curDist="${frontPath}/dist"
# serverProject="${serverRoot}/frontweb/${env}/${projectName}"



# cd $frontPath
# echo $(date "+%Y-%m-%d %H:%M:%S") + '## start git pull'
# $gitPath pull

# echo $(date "+%Y-%m-%d %H:%M:%S") + '## start rm -rf node_modules'
# rm -rf "${frontPath}/node_modules"

# echo $(date "+%Y-%m-%d %H:%M:%S") + '## start npm install'
# $npmPath i

# echo $(date "+%Y-%m-%d %H:%M:%S") + '## start npm run build:sit'
# $npmPath run build:sit
# echo $(date "+%Y-%m-%d %H:%M:%S") + '## build success'

# echo "mkdir ${serverProject}/old-version/${time2}"
# time2=$(date "+%Y%m%d%H%M%S")
# mkdir "${serverProject}/old-version/${time2}"

# echo "cp dist -> old-version/${time2}"
# cp -R "${serverProject}/dist" "${serverProject}/old-version/${time2}"

# echo $(date "+%Y-%m-%d %H:%M:%S") + "## 删除dist: rm -rm ${serverProject}/dist"
# rm -rf "${serverProject}/dist"
# echo $(date "+%Y-%m-%d %H:%M:%S") + "## 拷贝dist：cp -R ${curDist} ${serverProject}"
# cp -R $curDist $serverProject
# echo $(date "+%Y-%m-%d %H:%M:%S") + '## 拷贝成功'
